const fs = require('fs');
const path = require('path');

// Create test database directory if it doesn't exist
const testDbDir = path.join(__dirname, '../src/data');
if (!fs.existsSync(testDbDir)) {
  fs.mkdirSync(testDbDir, { recursive: true });
}

// Test database file
const testDbFile = path.join(testDbDir, 'widgets.test.db');

// Clean up test database before each test
beforeEach(() => {
  if (fs.existsSync(testDbFile)) {
    fs.unlinkSync(testDbFile);
  }
});

// Clean up after all tests
afterAll(() => {
  if (fs.existsSync(testDbFile)) {
    fs.unlinkSync(testDbFile);
  }
});

// Mock console methods to reduce noise during tests
global.console = {
  ...console,
  log: jest.fn(),
  error: jest.fn(),
  warn: jest.fn(),
  info: jest.fn()
};